package com.lighthouse.doc.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.common.annotation.Excel;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDate;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 文档信息对象 lh_doc_base_info
 *
 * @author ysz
 * @date 2023-03-22
 */
@Document(indexName = "doc-info-000001")
@Data
public class KnowledgeDocBaseInfo
{
    private static final long serialVersionUID = 1L;

    /** 文档主键 */
    @Id
    @Field(type = FieldType.Keyword)
    private String docId;

    /** 文档名称 */
    @Excel(name = "文档名称")
    @Field(type = FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
//    @Field(analyzer="ik_max_word", type = FieldType.Text)
    private String docName;

    /** 所属知识库 */
    @Excel(name = "所属知识库")
    @Field(type = FieldType.Keyword)
    private String repoId;

    /** 标签 */
    @Field(type = FieldType.Text)
    private List<Long> docTags;

    /** 标签名称 */
    @Field(type = FieldType.Text)
    private List<String> docTagsName;

    /** 文档内容纯文本 */
//    @Field(analyzer="ik_max_word", type = FieldType.Text)
    @Field(type = FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
    private String docContentText;

    /** 文档内容HTML */
    @Field(type = FieldType.Text)
    private String docContentHtml;

    /** 原始文档id */
    @Field(type = FieldType.Keyword)
    private String originId;

    /** 浏览量 */
    @Excel(name = "浏览量")
    @Field(type = FieldType.Keyword)
    private Long docViews;

    /** 点赞量 */
    @Excel(name = "点赞量")
    @Field(type = FieldType.Keyword)
    private Long docLikes;

    /** 收藏量 */
    @Excel(name = "收藏量")
    @Field(type = FieldType.Keyword)
    private Long docCollects;

    /** 评论量 */
    @Excel(name = "评论量")
    @Field(type = FieldType.Keyword)
    private Long docComments;

    /** 发布状态  0-草稿  1-待审核  2-已发布  3-存档  4-已删除*/
    @Field(type = FieldType.Keyword)
    private String docStatus;

    @Field(type = FieldType.Keyword)
    private String createBy;

    @Field(type = FieldType.Date, format = DateFormat.date)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate createTime;

    @Field(type = FieldType.Keyword)
    private String updateBy;

    @Field(type = FieldType.Date, format = DateFormat.date_hour_minute_second_millis)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    @Field(type = FieldType.Long)
    private Long createUser;

    @Field(type = FieldType.Keyword)
    private String createUserAvatar;

    public String getDocId() {
        return docId;
    }

    public void setDocId(String docId) {
        this.docId = docId;
    }

    public String getDocName() {
        return docName;
    }

    public void setDocName(String docName) {
        this.docName = docName;
    }

    public String getRepoId() {
        return repoId;
    }

    public void setRepoId(String repoId) {
        this.repoId = repoId;
    }

    public List<Long> getDocTags() {
        return docTags;
    }

    public void setDocTags(List<Long> docTags) {
        this.docTags = docTags;
    }

    public List<String> getDocTagsName() {
        return docTagsName;
    }

    public void setDocTagsName(List<String> docTagsName) {
        this.docTagsName = docTagsName;
    }

    public String getDocContentText() {
        return docContentText;
    }

    public void setDocContentText(String docContentText) {
        this.docContentText = docContentText;
    }

    public String getDocContentHtml() {
        return docContentHtml;
    }

    public void setDocContentHtml(String docContentHtml) {
        this.docContentHtml = docContentHtml;
    }

    public String getOriginId() {
        return originId;
    }

    public void setOriginId(String originId) {
        this.originId = originId;
    }

    public Long getDocViews() {
        return docViews;
    }

    public void setDocViews(Long docViews) {
        this.docViews = docViews;
    }

    public Long getDocLikes() {
        return docLikes;
    }

    public void setDocLikes(Long docLikes) {
        this.docLikes = docLikes;
    }

    public Long getDocCollects() {
        return docCollects;
    }

    public void setDocCollects(Long docCollects) {
        this.docCollects = docCollects;
    }

    public Long getDocComments() {
        return docComments;
    }

    public void setDocComments(Long docComments) {
        this.docComments = docComments;
    }

    public String getDocStatus() {
        return docStatus;
    }

    public void setDocStatus(String docStatus) {
        this.docStatus = docStatus;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public LocalDate getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDate createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Long getCreateUser() {
        return createUser;
    }

    public void setCreateUser(Long createUser) {
        this.createUser = createUser;
    }

    public String getCreateUserAvatar() {
        return createUserAvatar;
    }

    public void setCreateUserAvatar(String createUserAvatar) {
        this.createUserAvatar = createUserAvatar;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("KnowledgeDocBaseInfo{");
        sb.append("docId='").append(docId).append('\'');
        sb.append(", docName='").append(docName).append('\'');
        sb.append(", repoId='").append(repoId).append('\'');
        sb.append(", docTags='").append(docTags).append('\'');
        sb.append(", docTagsName='").append(docTagsName).append('\'');
        sb.append(", docContentText='").append(docContentText).append('\'');
        sb.append(", docContentHtml='").append(docContentHtml).append('\'');
        sb.append(", originId='").append(originId).append('\'');
        sb.append(", docViews=").append(docViews);
        sb.append(", createBy='").append(createBy).append('\'');
        sb.append(", createTime=").append(createTime);
        sb.append(", updateBy='").append(updateBy).append('\'');
        sb.append(", updateTime=").append(updateTime);
        sb.append(", createUser=").append(createUser);
        sb.append(", createUserAvatar=").append(createUserAvatar);
        sb.append(", docStatus=").append(docStatus);
        sb.append('}');
        return sb.toString();
    }

    public void setCreateInfo() {
        this.docId = UUID.fastUUID().toString();
        this.createBy = SecurityUtils.getLoginUser().getUser().getNickName();
        this.createTime = LocalDate.now();
        this.createUser = SecurityUtils.getLoginUser().getUser().getUserId();
        this.createUserAvatar = SecurityUtils.getLoginUser().getUser().getAvatar();
        this.docViews = 1L;
        this.docLikes = 0L;
        this.docCollects = 0L;
        this.docComments = 0L;
    }

    public void setUpdateInfo() {
        this.updateBy = SecurityUtils.getLoginUser().getUser().getNickName();
        this.updateTime = LocalDateTime.now();
    }
}
